package servlet;

import bean.PageBean;
import bean.ResumeBasicinfo;
import dao.ResumeDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ResumeServlet")
public class ResumeServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String type = request.getParameter("type");
        if ("list".equals(type)) {
            // 获取请求页码
            int pageNo = Integer.parseInt(request.getParameter("pageNo") == null ? "1" : request.getParameter("pageNo"));
            System.out.println(pageNo);
            ResumeDAO dao = new ResumeDAO();
            int recordCount = dao.getRecordCount();
            List<ResumeBasicinfo> list = dao.getPageList(pageNo, 5);
            PageBean<ResumeBasicinfo> pageBean = new PageBean<ResumeBasicinfo>();
            pageBean.setPageNo(pageNo);
            pageBean.setRecordCount(recordCount);
            pageBean.setPageData(list);
            request.setAttribute("pageBean", pageBean);
            request.getRequestDispatcher("manage/resumeList.jsp")
                    .forward(request, response);
        } else if ("select".equals(type)) {
            int resumeId = Integer.parseInt(request.getParameter("resumeId"));
            ResumeDAO dao = new ResumeDAO();
            ResumeBasicinfo resume = dao.selectBasicinfoByID(resumeId);
            request.setAttribute("resume", resume);
            request.getRequestDispatcher("manage/resumeView.jsp")
                    .forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

}
